const path = require('path')
const HtmlWebpackPlugin = require("html-webpack-plugin");

module.exports = {
    //打包入口
    entry: './src/index.tsx',
    //打包模式
    mode: "development",
    //打包输出文件名以及路径
    output: {
        filename: 'main.js',
        path: path.resolve(__dirname, 'dist'),
    },
    //设置webpack的解析文件拓展格式
    resolve: {
        extensions: [".js",".tsx"]
    },
    //devServer设置
    devServer: {
        hot: true, //随文件改动自动更新
        open: ['/'], //启动时默认打开浏览器
        port: 8000, //服务端口
        historyApiFallback: true //解决React开发的程序路由报错
    },
    //配置不同文件后缀对应使用的loader
    module: {
        rules: [
            {
                test: /\.css$/,
                exclude: /node_modules/,
                use: ["style-loader", "css-loader"],
            },
            {
                test: /\.(js|jsx|ts|tsx)$/,
                exclude: /node_modules/,
                use: ['babel-loader']
            }
        ],
    },
    plugins: [new HtmlWebpackPlugin({
        template: path.resolve(__dirname, "index.html"),
        inject: "body",
    }),]
};